package com.shwread.android.ui.page;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.LayoutParams;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.GlideUtil;
import com.NewActionHelp;
import com.google.gson.reflect.TypeToken;
import com.shwread.android.qysw.activity.GoodsSearchActivity;
import com.shwread.android.qysw.activity.GoodsSortActivity;
import com.shwread.android.qysw.activity.MainActivity;
import com.shwread.android.qysw.activity.NewGoodsMainActivity;
import com.shwread.android.qysw.activity.ShoppingCartActivity;
import com.shwread.android.qysw.activity.bannerListActivity;
import com.shwread.android.qysw10000227.R;
import com.shwread.android.ui.customview.BadgeView;
import com.shwread.android.ui.customview.GoodsPropPopView;
import com.shwread.android.ui.customview.GoodsPropViewListener;
import com.shwread.android.ui.customview.MyListView;
import com.shwread.android.ui.customview.QYViewPager;
import com.shwread.android.ui.dialog.NoNetDialog;
import com.shwread.android.ui.widget.refresh.PullToRefreshScrollView;
import com.shwread.android.ui.widget.refresh.PullToRefreshUtil;
import com.shwread.android.ui.widget.refresh.base.PullToRefreshBase;
import com.shwread.android.ui.widget.refresh.base.PullToRefreshBase.OnRefreshListener;
import com.shwread.http.base.ObjectHttpResponseHandler;
import com.shwread.http.base.TextHttpResponseHandler;
import com.shwread.http.util.Logger;
import com.shwread.httpsdk.util.NetUtil;
import com.tgx.tina.android.ipc.framework.IUIPage;

import org.apache.http.Header;
import org.json.JSONObject;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import base.tina.core.task.infc.ITaskResult;
import logic.bean.Area;
import logic.bean.EBannerInfo;
import logic.bean.GoodsBaseInfo;
import logic.bean.GoodsInfoColumn;
import logic.bean.GoodsSkuMapInfo;
import logic.bean.PageDto;
import logic.bean.RecommendInfo;
import logic.bean.ShoppingCart;
import logic.constants.AppConfig;
import logic.constants.DefaultConsts;
import logic.dao.AreaDao;
import logic.dao.ShoppingCartDao;
import logic.util.MoneyUtil;
import logic.util.NetworkUtil;
import logic.util.Utils;


/**
 * 电商平台
 *
 * @author 刘宾
 * @date 2015年1月15日 上午9:37:56
 */
public class ECommercePage
        extends
        AbstractUIPage<MainActivity>
        implements
        OnClickListener {

    private static final int red = Color.parseColor("#ff3300");
    private static ECommercePage instance;
    private TextView tvTitle;
    //	private ImageView               ivPersion;
    private ImageView ivMenu;
    private ImageView btnSearch;
    private PullToRefreshScrollView contentView;                                         //主页面视图
    private LinearLayout ll_ecommerce_contentview;                            //主视图
    private List<EBannerInfo> banners = new ArrayList<EBannerInfo>();
    private QYViewPager vbPager;
    private ViewPagerAdapter vbAdapter;
    private List<View> bannerList = new ArrayList<View>();
    Runnable action = new Runnable() {
        @Override
        public void run() {
            int cItem = vbPager.getCurrentItem();
            cItem++;
            if (cItem >= vbAdapter.getCount()) {
                cItem = 0;
            }
            vbPager.setCurrentItem(cItem);
        }
    };
    private int bannersLength;
    private int bannerFlag;                                          //数据加载方式  0 为首次加载 1 为刷新 2为加载更多
    //热门活动
    private View vRecommend;                                          //热门推荐视图
    //	private ViewPager               viewPagerRecommend;
    private Gallery vGallery;
    private LinearLayout layDot;
    private ImageView[] indicators = null;
    private List<ImageView> lvDot = new ArrayList<ImageView>();
    private int currentItem = 0;
    private int recommendItemLength = 4;                             //数据的原始长度
    private RecommendPagerAdapter recommendPagerAdapter;
    private List<RecommendInfo> recommendList = new ArrayList();
    private int recommendFlag;                                       //数据请求的方式  0为首次加载，1为上拉刷新  2为下拉加载
    //大家都在买
    private AllBuyAdapter allBuyAdapter;
    private List<GoodsBaseInfo> allBuyList = new ArrayList<GoodsBaseInfo>();
    private View vAllBuy;
    private MyListView allBuyXListView;
    private int buyCurrrentpage = 1;                             //当前页
    private int buyTotalPage;                                        //总的页数
    private int buyTotalNum;                                         //总的条目
    private int buyPageNum = 5;                             //每页显示的数目
    private int buyFlag;                                             //数据请求的方式  0为首次加载，1为上拉刷新  2为下拉加载
    //加载动画
    private RelativeLayout rlay_loading;
    private AnimationDrawable animationDrawable;
    private ImageView loadingImg;
    private boolean isLastSuccess = false;                         //数据最后一次加载成功或者失败的标志
    private GoodsPropPopView goodsPropView;
    //购物车视图
    private ImageView ivAddShoppingCar;
    private BadgeView badgeView;
    private ShoppingCartDao shoppingCartDao;
    private boolean isloop = true;                          //是否自动换页

    public ECommercePage(MainActivity t) {
        super(t);
    }

    public static ECommercePage getInstance(MainActivity bActivity) {
        if (instance == null) {
            instance = new ECommercePage(bActivity);
        } else {
            instance.setActivity(bActivity);
        }
        return instance;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.common_header_back:
                //				Utils.ToastShow(bActivity, "点击菜单");
                //				bActivity.startActivity(new Intent(bActivity, GoodsMainActivity.class));
                bActivity.startActivity(new Intent(bActivity, GoodsSortActivity.class));
                break;
            case R.id.common_header_search:
                bActivity.startActivity(new Intent(bActivity, GoodsSearchActivity.class));
                break;
//			case R.id.common_header_persion:
//				//				Utils.ToastShow(bActivity, "点击个人中心");
//				//				Intent intent = new Intent(bActivity, MyGoodsActivity.class);
//				//				intent.putExtra(DefaultConsts.ORDER_DETAIL_ORDER_ID, 1);
//				bActivity.goPersonalActivity();
//				//				bActivity.startActivity(intent);
//				break;
            case R.id.ecommerce_add_shopping_car_iv:
                bActivity.startActivity(new Intent(bActivity, ShoppingCartActivity.class));
                //				Utils.ToastShow(bActivity, "您点击了购物车");

                break;
            default:
                break;
        }
    }

    @Override
    public <E extends Activity> View createView(E arg0, int arg1) {
        if (null != curMyView) return curMyView;
        curMyView = bActivity.getLayoutInflater().inflate(R.layout.e_commerce, null);
        shoppingCartDao = ShoppingCartDao.getInstance(bActivity);

        initView();
        setListener();

        getBanner(0);
        getAllBuy(0);
        getRecommend(0);
        getShoppingCartCount();
        gotoTop();
        return curMyView;
    }

    @SuppressLint("UseSparseArrays")
    public void initView() {
        tvTitle = (TextView) curMyView.findViewById(R.id.common_header_name);
        tvTitle.setText(bActivity.getResources().getString(R.string.maintab_e_commerce));
//		ivPersion = (ImageView) curMyView.findViewById(R.id.common_header_persion);
        //		ivPersion.setVisibility(View.VISIBLE);
        ivMenu = (ImageView) curMyView.findViewById(R.id.common_header_back);
        ivMenu.setImageResource(R.drawable.e_commerce_menu_icon);
        ivMenu.setVisibility(View.VISIBLE);
        btnSearch = (ImageView) curMyView.findViewById(R.id.common_header_search);
        btnSearch.setVisibility(View.VISIBLE);

        ll_ecommerce_contentview = (LinearLayout) curMyView.findViewById(R.id.ll_newenterprise_contentview);

        contentView = (PullToRefreshScrollView) curMyView.findViewById(R.id.e_commerce_psview);
        PullToRefreshUtil.initLabel(bActivity, contentView);

        //加载动画
        rlay_loading = (RelativeLayout) curMyView.findViewById(R.id.common_loading_layout);
        loadingImg = (ImageView) curMyView.findViewById(R.id.common_loading__img);

        //banner
        vbPager = (QYViewPager) curMyView.findViewById(R.id.enterprise_head_pager);
        vbPager.setVisibility(View.GONE);
        vbAdapter = new ViewPagerAdapter();
        vbPager.setAdapter(vbAdapter);

        //		bannerView = new SmartImageView[4];
        //		for (int i = 0; i < 4; i++)
        //		{
        //			if (Utils.isNotEmpty(banners.get(i).getPicUrl()))
        //			{
        //				bannerView[i].setImageUrl(banners.get(i).getPicUrl());
        //			}
        //			bannerList.add(bannerView[i]);
        //		}
        //		vbAdapter = new ViewPagerAdapter();
        //		vbPager.setAdapter(vbAdapter);
        //		vbPager.setCurrentItem(0);
        // 设置选中的条目为中间 某一个循环小组的第一张
        //		vbPager.setCurrentItem((Integer.MAX_VALUE / 2) - (Integer.MAX_VALUE / 2) % bannersLength);

        //热门推荐

        vRecommend = bActivity.getLayoutInflater().inflate(R.layout.recommend_gallery, null);
        vGallery = (Gallery) vRecommend.findViewById(R.id.recommend_gallery);
        vRecommend.setVisibility(View.GONE);

        //指示器视图
        layDot = (LinearLayout) vRecommend.findViewById(R.id.recommend_viewpager_dot);
        //		indicators = new ImageView[6];
        //		//动态添加小圆点
        //		for (int i = 0; i < 6; i++)
        //		{
        //			//循环加入指示器
        //			indicators[i] = new ImageView(bActivity);
        //
        //			if (i == currentItem)
        //			{
        //				indicators[i].setBackgroundResource(R.drawable.dot_selected_bg);
        //			}
        //			else
        //			{
        //				indicators[i].setBackgroundResource(R.drawable.dot_unselected_bg);
        //			}
        //			layDot.addView(indicators[i]);
        //		}
        //		//设置默认进入的位置
        //		vGallery.setSelection((Integer.MAX_VALUE / 2) - (Integer.MAX_VALUE / 2) % ItemLength);
        //		vGallery.setUnselectedAlpha(0.45F);//设置未选中图片的透明度
        recommendPagerAdapter = new RecommendPagerAdapter();
        vGallery.setAdapter(recommendPagerAdapter);

        ll_ecommerce_contentview.addView(vRecommend);

        //大家都在买
        vAllBuy = bActivity.getLayoutInflater().inflate(R.layout.all_buy_lay, null);
        allBuyXListView = (MyListView) vAllBuy.findViewById(R.id.e_commerce_all_buy_list);
        vAllBuy.setVisibility(View.GONE);

        allBuyAdapter = new AllBuyAdapter();
        allBuyXListView.setAdapter(allBuyAdapter);

        ll_ecommerce_contentview.addView(vAllBuy);

        //购物车视图
        ivAddShoppingCar = (ImageView) curMyView.findViewById(R.id.ecommerce_add_shopping_car_iv);
        //		tvShoppingCarNum = (TextView) curMyView.findViewById(R.id.ecommerce_add_shopping_car_count_tv);

        badgeView = new BadgeView(bActivity, ivAddShoppingCar);
        badgeView.setTextSize(10);
        badgeView.setBadgePosition(2);// 2代表右上角
        badgeView.setBackgroundResource(R.drawable.red_radio);
        badgeView.setTextColor(bActivity.getResources().getColor(android.R.color.white));
        badgeView.show();
    }

    public void setListener() {
//		ivPersion.setOnClickListener(this);
        ivMenu.setOnClickListener(this);
        btnSearch.setOnClickListener(this);
        ivAddShoppingCar.setOnClickListener(this);

        vbPager.setOnPageChangeListener(new OnPageChangeListener() {

            @Override
            public void onPageSelected(int i) {
                // TODO Auto-generated method stub
                int pageIndex = i;
                if (i == 0) {
                    // 当视图在第一个时，将页面号设置为图片的最后一张。
                    pageIndex = banners.size() - 2;
                } else if (i == banners.size() - 1) {
                    // 当视图在最后一个是,将页面号设置为图片的第一张。
                    //					pageIndex = 0;
                    pageIndex = 1;
                }
                if (i != pageIndex) {
                    vbPager.setCurrentItem(pageIndex, false);
                }

                looperBanner();
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
                // TODO Auto-generated method stub

            }
        });

        vGallery.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (position >= recommendItemLength) {
                    position = position % recommendItemLength;
                }
                currentItem = position;
                setPoint();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                // TODO Auto-generated method stub

            }
        });

        vGallery.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                position = position % recommendItemLength; //修改position
                //判断点击的是否为中间的item 如果是则添加跳转事件，否则不进行任何操作
                if (position == currentItem) {
                    //					Utils.showToast(bActivity, "即将进入详情页");
                    RecommendInfo info = (RecommendInfo) parent.getAdapter().getItem(position);
                    gotoGoodsDetailPageActivity(info.getGoodsDto().getBaseUrl(), info.getGoodsDto().getDetailUrl(), info.getGoodsDto().getGoodsId(), DefaultConsts.WAP_TAG_FROM_RECOMMEND, info.getId(), info.getFreeMoney());
                }

            }
        });

        allBuyXListView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //				Utils.showToast(bActivity, "点我有惊喜");
                GoodsBaseInfo info = (GoodsBaseInfo) parent.getAdapter().getItem(position);
                gotoGoodsDetailPage(info.getBaseUrl(), info.getDetailUrl(), info.getGoodsId(), DefaultConsts.WAP_TAG_FROM_ALL_BUY);
            }
        });

        contentView.setOnRefreshListener(new OnRefreshListener<ScrollView>() {

            @Override
            public void onRefresh(PullToRefreshBase<ScrollView> refreshView) {
                if (contentView.isHeaderShown()) {
                    refrush();
                } else if (contentView.isFooterShown()) {
                    loadMore();
                }
            }

        });

    }

    //	private void shoppingTest() {
    //		ShoppingCartDao dao = ShoppingCartDao.getInstance(context);
    //		ShoppingCart obj = new ShoppingCart("13064796376", 111L, 10000000, "这是标题111", "亏本大甩卖111", "简介test111", "", 1, 10000, "n", 222L, "json1", System.currentTimeMillis());
    //		ShoppingCart obj1 = new ShoppingCart("13064796376", 112L, 10000001, "这是标题222", "亏本大甩卖222", "简介test222", "", 2, 10000, "n", 223L, "json2", System.currentTimeMillis());
    //		ShoppingCart obj2 = new ShoppingCart("13064796376", 113L, 10000002, "这是标题333", "亏本大甩卖333", "简介test333", "", 3, 10000, "n", 224L, "json3", System.currentTimeMillis());
    //		long id = dao.add(obj);
    //		dao.add(obj1);
    //		dao.add(obj2);
    //		ShoppingCart bean = dao.query("13064796376", id);
    //		long count = dao.queryCount("13064796376");
    //		int deleteCount = dao.deleteById("13064796376", id);
    //	}

    @Override
    public int enter(IUIPage<?> arg0) {
        if (NetworkUtil.isNetAvailable(bActivity)) {

            if (!isLastSuccess) {
                try {
                    startLoading();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            //			login();
            //			buyCurrrentpage = 1;
            //			getBanner(0);
            //			getAllBuy(0);
            //			getRecommend(0);
            //			getShoppingCartCount();
            gotoTop();
        } else {
            new NoNetDialog(bActivity).show();
        }
        //		shoppingTest();
        return 0;
    }

    @Override
    public int leave(IUIPage<?> arg0) {
        if (instance != null) {
            instance = null;
            isloop = false;

        }
        return 0;
    }

    @Override
    public void notifyView(int arg0, Bundle arg1) {
        if (arg0 == DefaultConsts.PAGE_ONRESUME_CODE) {
            getShoppingCartCount();
        }

    }

    @Override
    public void setStatus(int arg0) {

    }

    @Override
    public View updateView(int arg0, ITaskResult arg1) {
        return null;
    }

    /**
     * 跳转到商品信息页面
     * 该页面是一个WAP 页面需要传入一些信息
     *
     * @param baseUrl   商品基本信息的Url
     * @param detailUrl 商品详情的Url
     * @param goodsId   商品的Id
     * @type 从哪个页面跳转
     */
    private void gotoGoodsDetailPage(String baseUrl, String detailUrl, long goodsId, int type) {
        Intent intent = new Intent(bActivity, NewGoodsMainActivity.class);
        intent.putExtra(DefaultConsts.GOODS_BASE_URL_TO_WAP, baseUrl);
        intent.putExtra(DefaultConsts.GOODS_DETAIL_URL_TO_WAP, detailUrl);
        intent.putExtra(DefaultConsts.GOODS_ID_TO_WAP, goodsId);
        intent.putExtra(DefaultConsts.WAP_FROM_TYPE, type);
        //		intent.putExtra(name, value);
        bActivity.startActivity(intent);
    }

    private void gotoGoodsDetailPageActivity(String baseUrl, String detailUrl, long goodsId, int type, long activityId, int freeMoney) {
        Intent intent = new Intent(bActivity, NewGoodsMainActivity.class);
        intent.putExtra(DefaultConsts.GOODS_BASE_URL_TO_WAP, baseUrl);
        intent.putExtra(DefaultConsts.GOODS_DETAIL_URL_TO_WAP, detailUrl);
        intent.putExtra(DefaultConsts.GOODS_ID_TO_WAP, goodsId);
        intent.putExtra(DefaultConsts.WAP_FROM_TYPE, type);
        intent.putExtra(DefaultConsts.GOODS_ACTIVITY_PRICE_ID, activityId);
        intent.putExtra(DefaultConsts.GOODS_FREE_MONEY_TO_WAP, freeMoney);
        bActivity.startActivity(intent);
    }

    /**
     * 获取购物车信息
     */

    private void getShoppingCartCount() {
        try {
            String str = NewActionHelp.getAccount();
            long c = shoppingCartDao.queryCount(NewActionHelp.getAccount());
            if (c <= 0) {
                badgeView.hide();
            } else {

                badgeView.setText(String.valueOf(c));
                badgeView.show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * banner 的自动滑动
     */
    private void looperBanner() {
        if (banners.size() <= 1) return;
        vbPager.removeCallbacks(action);
        vbPager.postDelayed(action, 3000);
    }

    /*
     * (non-Javadoc)
     * @see com.shwread.android.ui.page.AbstractUIPage#dispose()
     */
    @Override
    public void dispose() {
        super.dispose();
        if (null != vbPager && null != action) vbPager.removeCallbacks(action);
    }

    /**
     * 回到顶部
     */
    private void gotoTop() {
        if (null != contentView) {
            contentView.post(new Runnable() {
                @Override
                public void run() {
                    contentView.getRefreshableView().scrollTo(0, 0);
                }
            });
        }
    }

    /******************* 加载数据 ****************************************/

    /**
     * 登陆操作
     */
    private void login() {
        NewActionHelp.init(NetUtil.getImei(bActivity), NetUtil.getPsdnIp(), false);
        //		NewActionHelp.setAccount("15868129524");
        //		NewActionHelp.userLogin(bActivity, "15868129524", "123456", new TextHttpResponseHandler()
        //		NewActionHelp.userLogin(bActivity, "18768198044", "123456", new TextHttpResponseHandler()
        NewActionHelp.userLogin(bActivity, "13003621230", "123456", new TextHttpResponseHandler() {

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                Logger.json(responseString);
                System.out.println("1111111111111111111  -----login----d登陆成功");
                //				Toast.makeText(context,  "onSuccess"+responseString, Toast.LENGTH_SHORT).show();

                try {
                    final String key = new JSONObject(responseString).getString("returnObject");
                    NewActionHelp.setLoginKey(key);
                    //					                     NewActionHelp.setAccount("15868129524");
                    NewActionHelp.setAccount("13003621230");
                    //					NewActionHelp.setAccount("18768198044");
                    //					NewActionHelp.setAccount("15868129524");
                    getBanner(0);
                    getAllBuy(0);
                    getAllCity();
                    getRecommend(0);
                    getShoppingCartCount();
                    //	                NewActionHelp.qryAccountInfo(context, "13064796376", new ObjectHttpResponseHandler<UserBean>()
                    //	          		                  		{
                    //
                    //	          		                  			@Override
                    //	          		                              public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                    //    	          		                  			tvContent.append("\n\n onFailure --> "+responseString+","+headers.toString());
                    //    	          									scrollToBottom();
                    //	          		                              }
                    //
                    //	          		                  			@Override
                    //	          		                              public void onSuccess(int statusCode, Header[] headers, UserBean t, String responseString) {
                    //    	          		                  			tvContent.append("\n\n onSuccess --> "+t.toString());
                    //    	          									scrollToBottom();
                    //	          		                              }
                    //
                    //												@Override
                    //                                                protected Type getType() {
                    //	                                                return new TypeToken<UserBean>(){}.getType();
                    //                                                }
                    //	          		                  		});
                    //	                NewActionHelp.qryB2CBanners(context, "13064796376", 1, 4, handler);
                    //	                NewActionHelp.qrySellBestGoods(context, "13064796376", 1, 3, handler);
                    //	                NewActionHelp.qryGoodsItems(context, "13064796376", handler);
                    //	                NewActionHelp.qryGoodsByItemId(context, "13064796376", 2L, 1, 10, handler);
                } catch (Exception e) {
                    stopLoading();
                    e.printStackTrace();
                    System.out.println("1111111111111111111  ------------接口调用异常");
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                Logger.e(throwable);
                Logger.i("错误验证码----------" + String.valueOf(statusCode));
                stopLoading();
            }
        });
    }

    /**
     * 加载城市列表数据
     */
    private void getAllCity() {
        final long count = AreaDao.getInstance(context).queryCount();
        if (count == 0 || count < 3000) {
            AreaDao.getInstance(context).deleteAll();
            NewActionHelp.qryCityName(bActivity, 1, new CityHandler());
            NewActionHelp.qryCityName(bActivity, 2, new CityHandler());
            NewActionHelp.qryCityName(bActivity, 3, new CityHandler());
        }

    }

    /**
     * 加载banner 数据
     * int a 0 为首次进入 1为上拉刷新
     */
    private void getBanner(int a) {
        this.bannerFlag = a;
        NewActionHelp.qryB2CBanners(context, 1, 4, new GetBannerAction());
    }

    /**
     * 加载大家都在买 数据
     * int a 0 为首次加载 1 为刷新 2为加载更多
     */

    private void getAllBuy(int a) {
        this.buyFlag = a;
        NewActionHelp.qrySellBestGoods(context, buyCurrrentpage, buyPageNum, new GetAllBuyAction());

    }

    /**
     * 加载商品推荐 数据
     * int a 0 为首次加载 1 为刷新 2为加载更多
     */

    private void getRecommend(int a) {
        this.recommendFlag = a;
        NewActionHelp.qryEPGoodsForHot(bActivity, 0, new GetRecommendAction());

    }

    /********************** Action 监听事件 start ***********************************/

    /**
     * 上拉加载
     */
    private void loadMore() {
        //		Utils.showToast(bActivity, "下拉加载");
        if (buyTotalNum <= buyPageNum || buyTotalPage <= buyCurrrentpage) {
            PullToRefreshUtil.setLoadLabel(contentView, "没有更多数据了");
            contentView.onRefreshComplete();
        } else {
            PullToRefreshUtil.setLoadLabel(contentView, "正在加载中");
            buyCurrrentpage++;
            getAllBuy(2);
        }
    }

    /**
     * 下拉刷新
     */
    private void refrush() {
        //		Utils.showToast(bActivity, "上拉刷新");
        buyCurrrentpage = 1;
        getAllBuy(1);
        getBanner(1);
        getRecommend(1);
        getShoppingCartCount();
    }

    /**
     * 动态添加小圆点
     *
     * @param 实际数据大小
     */
    private void creatDotView(int a) {
        if (lvDot.size() > 0) {
            lvDot.clear();
            layDot.removeAllViews();
        }
        indicators = new ImageView[a];
        //动态添加小圆点
        for (int i = 0; i < a; i++) {
            //循环加入指示器
            indicators[i] = new ImageView(bActivity);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); // , 1是可选写的
            lp.setMargins(10, 5, 10, 5);
            indicators[i].setLayoutParams(lp);

            if (i == currentItem) {
                indicators[i].setBackgroundResource(R.drawable.dot_selected_bg);
            } else {
                indicators[i].setBackgroundResource(R.drawable.dot_unselected_bg);
            }
            lvDot.add(indicators[i]);
        }
        for (int i = 0; i < lvDot.size(); i++) {
            layDot.addView(lvDot.get(i));
        }
    }

    /**
     * 设置指示器位置
     */
    private void setPoint() {
        for (int i = 0; i < recommendItemLength; i++) {
            if (i == currentItem) {
                indicators[i].setBackgroundResource(R.drawable.dot_selected_bg);
            } else {
                indicators[i].setBackgroundResource(R.drawable.dot_unselected_bg);
            }
        }
    }

    /**
     * 开始加载动画
     */
    private void startLoading() {
        rlay_loading.setVisibility(View.VISIBLE);
        loadingImg.setBackgroundResource(R.drawable.home_progress);
        animationDrawable = (AnimationDrawable) loadingImg.getBackground();
        animationDrawable.start();
    }

    /**
     * 停止加载动画
     */
    private void stopLoading() {
        rlay_loading.setVisibility(View.GONE);
        if (animationDrawable != null && animationDrawable.isRunning()) {
            animationDrawable.stop();
        }
    }

    /********************** Action 监听事件 end ***********************************/

    /******************** 一些辅助性的方法 ****************************************/

    /**
     * 关闭加载的动画
     * int a 0 为首次进入 关闭加载动画 1 为contentView 事件
     */
    private void closeLoading(int a) {
        if (a == 0) {
            stopLoading();
        } else {
            contentView.onRefreshComplete();
        }

    }

    /**
     * 点击添加购物车后的操作
     * 根据商品Id获取商品的SUK
     */
    //	private void addToShoppingCar(long goodsId) {
    //		if (NetWorkUtil.isNetAvailable(bActivity))
    //		{
    //			NewActionHelp.qryGoodsBase(bActivity, 2L, new getGoodsBaseAction());
    //		}
    //		else
    //		{
    //			new NoNetDialog(bActivity);
    //		}
    //
    //	}

    //	private void addToShoppingCar(long goodsId) {
    //		if (NetworkUtil.isNetAvailable(bActivity))
    //		{
    //			NewActionHelp.qryGoodsBase(bActivity, goodsId, new getGoodsBaseAction());
    //		}
    //		else
    //		{
    //			new NoNetDialog(bActivity);
    //		}
    //
    //	}
    private void addToShoppingCarActivity(long goodsId, long activityId, int freeMoney) {
        if (NetworkUtil.isNetAvailable(bActivity)) {
            NewActionHelp.qryGoodsBase(bActivity, goodsId, new getGoodsBaseAction(activityId, freeMoney));
        } else {
            new NoNetDialog(bActivity);
        }

    }

    /**
     * 获取banner的监听事件
     */

    private class GetBannerAction
            extends
            ObjectHttpResponseHandler<List<EBannerInfo>> {

        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            Logger.e("banner----------------->" + responseString);
            System.out.println("1111111111111111111  -----banner----调用借口失败");

            closeLoading(bannerFlag);
            isLastSuccess = false; //数据加载成功与否的标志
            vbPager.setVisibility(View.GONE); //数据加载失败  需要隐藏视图

        }

        public void onSuccess(int statusCode, Header[] headers, List<EBannerInfo> object, String responseString) {
            Logger.d("banner----------------->" + responseString);
            System.out.println("1111111111111111111  -----banner----调用借口成功");

            //关闭加载动画
            closeLoading(bannerFlag);
            isLastSuccess = true;
            //			if (bannerFlag != 0) contentView.onRefreshComplete();
            if (object != null && object.size() > 0) {
                if (banners.size() > 0) banners.clear();
                if (bannerList.size() > 0) bannerList.clear();
                List<EBannerInfo> temp = (List<EBannerInfo>) object;
                //以下三行代码是为了把第一张与最后一张数据填充到list里面形成一个循环
                banners.add(temp.get(temp.size() - 1));
                banners.addAll(temp);
                banners.add(temp.get(0));

                bannersLength = banners.size();
                for (int i = 0; i < banners.size(); i++) {

                    ImageView imageView = new ImageView(context);
                    LayoutParams layoutParams = new LayoutParams();
                    layoutParams.height = LayoutParams.MATCH_PARENT;
                    layoutParams.width = LayoutParams.MATCH_PARENT;
                    imageView.setLayoutParams(layoutParams);
                    imageView.setScaleType(ScaleType.FIT_XY);
                    if (Utils.isNotEmpty(banners.get(i).getPicUrl())) {
                        //						imageView.setImageUrl(banners.get(i).getPicUrl());
                        GlideUtil.load(context,banners.get(i).getPicUrl(), R.drawable.bg_big_image,imageView);
                    } else {
                        imageView.setImageResource(R.drawable.bg_big_image);
                    }

                    bannerList.add(imageView);

                }

                // 设置选中的条目为中间 某一个循环小组的第一张
                //				vbPager.setCurrentItem((Integer.MAX_VALUE / 2) - (Integer.MAX_VALUE / 2) % bannersLength);
                vbPager.setCurrentItem(1);
                vbPager.setVisibility(View.VISIBLE);
                isloop = true;
                looperBanner();
                vbAdapter.notifyDataSetChanged();
                System.out.println("1111111111111111111  -----banner----数据解析成功");
            } else {
                //数据为空时需要隐藏视图
                vbPager.setVisibility(View.GONE);
            }
        }

        @Override
        public Type getType() {

            return new TypeToken<List<EBannerInfo>>() {
            }.getType();
        }

    }

    /**
     * getAllBuyAction 监听事件
     */

    private class GetAllBuyAction
            extends
            ObjectHttpResponseHandler<GoodsInfoColumn> {
        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            Logger.d("getAllBuyAction----------------->" + responseString);
            System.out.println("1111111111111111111  -----大家都在买----调用借口失败");
            //关闭加载动画
            closeLoading(buyFlag);
            isLastSuccess = false;
            vAllBuy.setVisibility(View.GONE);
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, GoodsInfoColumn object, String responseString) {
            Logger.d("getAllBuyAction----------------->" + responseString);
            System.out.println("1111111111111111111  -----大家都在买----调用借口成功");

            //关闭加载动画
            closeLoading(buyFlag);
            isLastSuccess = true;

            PageDto pageDto = object.getPageDto();
            buyTotalNum = pageDto.getTotalNum();
            buyTotalPage = pageDto.getTotalPage();

            if (object.getGoodsList() != null && object.getGoodsList().size() > 0) {
                vAllBuy.setVisibility(View.VISIBLE);
                if (buyFlag != 2) {
                    if (allBuyList.size() > 0) allBuyList.clear();

                    allBuyList.addAll(object.getGoodsList());
                    allBuyAdapter.notifyDataSetChanged();
                } else {
                    allBuyList.addAll(object.getGoodsList());
                    allBuyAdapter.notifyDataSetChanged();
                }
                System.out.println("1111111111111111111  -----大家都在买----数据解析成功");
            } else {
                //数据为空 需要隐藏视图
                vAllBuy.setVisibility(View.GONE);
            }
        }

        @Override
        public Type getType() {
            return new TypeToken<GoodsInfoColumn>() {
            }.getType();
        }
    }

    /**
     * GetRecommendAction 监听事件
     */

    private class GetRecommendAction
            extends
            ObjectHttpResponseHandler<List<RecommendInfo>> {
        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            Logger.d("GetRecommendAction----------------->" + responseString);
            System.out.println("1111111111111111111  -----热门活动----调用借口失败");
            //关闭加载动画
            closeLoading(recommendFlag);
            isLastSuccess = false;
            vRecommend.setVisibility(View.GONE);
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, List<RecommendInfo> object, String responseString) {
            Logger.d("GetRecommendAction----------------->" + responseString);
            System.out.println("1111111111111111111  -----热门活动----调用借口成功");

            //关闭加载动画
            closeLoading(recommendFlag);
            isLastSuccess = true;

            if (object != null && object.size() > 0) {
                //动态添加小圆点
                creatDotView(object.size());

                if (recommendList.size() > 0) recommendList.clear();
                recommendList.addAll(object);
                recommendItemLength = recommendList.size();

                //					recommendPagerAdapter = new RecommendPagerAdapter();
                //				vGallery.setAdapter(recommendPagerAdapter);
                //				//设置默认进入的位置
                vGallery.setSelection((Integer.MAX_VALUE / 2) - (Integer.MAX_VALUE / 2) % recommendItemLength);
                vGallery.setUnselectedAlpha(0.45F);//设置未选中图片的透明度
                recommendPagerAdapter.notifyDataSetChanged();
                vRecommend.setVisibility(View.VISIBLE);
                System.out.println("1111111111111111111  -----热门活动----数据解析成功");
            } else {
                //数据为空 需要隐藏视图
                vRecommend.setVisibility(View.GONE);
            }
        }

        @Override
        public Type getType() {
            return new TypeToken<List<RecommendInfo>>() {
            }.getType();
        }
    }

    /**
     * 点击购物车 监听事件
     */
    private class getGoodsBaseAction
            extends
            ObjectHttpResponseHandler<GoodsBaseInfo> {
        private long activityId;
        private int freeMoney;

        public getGoodsBaseAction(long activityId, int freeMoney) {
            this.activityId = activityId;
            this.freeMoney = freeMoney;
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            if (statusCode < 1000) {

                Utils.ToastShow(bActivity, "网络错误");
            } else {
                Utils.ToastShow(bActivity, "请求出错");
            }

        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, final GoodsBaseInfo object, String responseString) {
            System.out.println("xxxxxxxxxxxxxxxxxxx_" + responseString);

            goodsPropView = new GoodsPropPopView(bActivity, object, new ShoppingCartAddListener(object), activityId, freeMoney);

            bActivity.getUIHandler().post(new Runnable() {

                @Override
                public void run() {
                    if (goodsPropView != null) goodsPropView.showWindow();
                }
            });

        }

        @Override
        public Type getType() {
            return new TypeToken<GoodsBaseInfo>() {
            }.getType();
        }

    }

    /**
     * 加入购物车popView监听器
     *
     * @author xuzhijun
     * @date 2015年4月17日 下午12:40:13
     */
    private class ShoppingCartAddListener
            implements
            GoodsPropViewListener {

        private GoodsBaseInfo goodsInfo;

        public ShoppingCartAddListener(GoodsBaseInfo goodsInfo) {
            this.goodsInfo = goodsInfo;
        }

        @Override
        public void OK(GoodsSkuMapInfo goodsSkuMapInfo, String propString, int count, Dialog d, long activityId, int freeMoney) {
            shoppingCartDao = ShoppingCartDao.getInstance(bActivity);
            ShoppingCart goods;
            if (goodsSkuMapInfo != null) {
                goods = new ShoppingCart(NewActionHelp.getAccount(), goodsInfo.getGoodsId(), Integer.parseInt(AppConfig.getEnterpriseId()), goodsInfo.getTitle(), goodsInfo.getSellPoint(), goodsInfo.getShortDesc(), goodsInfo.getCoverUrl(), count, goodsSkuMapInfo.getPrice() - goodsInfo.getActivityPrice(), "n", goodsSkuMapInfo.getSkuId(), propString, System.currentTimeMillis());
            } else {
                goods = new ShoppingCart(NewActionHelp.getAccount(), goodsInfo.getGoodsId(), Integer.parseInt(AppConfig.getEnterpriseId()), goodsInfo.getTitle(), goodsInfo.getSellPoint(), goodsInfo.getShortDesc(), goodsInfo.getCoverUrl(), count, goodsInfo.getSalePrice(), "n", 0, "", System.currentTimeMillis());
            }
            goods.activityId = activityId;
            goods.freeMoney = freeMoney;
            goods.goodsDetailUrl = goodsInfo.getDetailUrl();
            goods.baseUrl = goodsInfo.getBaseUrl();

            if (shoppingCartDao.add(goods) != -1) {
                Utils.ToastShow(bActivity, "添加成功");
                //				refrush();
                getShoppingCartCount();
                d.dismiss();
            } else {
                Utils.ToastShow(bActivity, "添加失败");
            }
        }

    }

    /**
     * 加载城市列表数据 监听事件
     */
    private class CityHandler
            extends
            ObjectHttpResponseHandler<List<Area>> {
        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            Logger.e(responseString, throwable);
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, final List<Area> object, String responseString) {
            Logger.d("获取城市数据" + object.size() + "条，AreaType" + object.get(0).areaType);
            new Thread() {
                public void run() {
                    AreaDao.getInstance(bActivity).addList(object);
                }

                ;
            }.start();
        }

        @Override
        public Type getType() {
            return new TypeToken<List<Area>>() {
            }.getType();
        }
    }

    /**
     * 点击添加购物车后的回调函数
     */

    /*******************************
     * Banner start
     *********************************/

    class ViewPagerAdapter
            extends
            PagerAdapter {
        public int curposition; //

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return (bannerList == null || bannerList.size() == 0) ? 0 : bannerList.size();
            //			bannersLength = banners.size();
            //			return (banners == null || banners.size() == 0) ? 0 : Integer.MAX_VALUE; //为了循环显示
        }

        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {
            // TODO Auto-generated method stub
            return arg0 == arg1;
        }

        //		@Override
        //		public Object instantiateItem(View container, final int position) {
        //						if (position >= bannersLength)
        //						{
        //							curposition = position % bannersLength;
        //						}
        //						else
        //						{
        //							curposition = position;
        //						}
        //			bannerList.get(curposition).setOnClickListener(new OnClickListener()
        //			{
        //
        //				@Override
        //				public void onClick(View v) {
        //					EBannerInfo bannerInfo = banners.get(curposition);
        //					//					Utils.showToast(context, "您点击了" + position + "图片");
        //					// type 类型 int  1为单个商品  2 为多个商品
        //					switch (bannerInfo.getType()) {
        //						case 1:
        //							gotoGoodsDetailPage(bannerInfo.getBannerUrl(), bannerInfo.getBannerUrl(), Long.parseLong(bannerInfo.getContent()), bannerInfo.getType());
        //							break;
        //						case 2:
        //							Intent intent = new Intent(bActivity, bannerListActivity.class);
        //							intent.putExtra(DefaultConsts.GOODS_BASE_URL_TO_WAP, bannerInfo.getBannerUrl());
        //							intent.putExtra(DefaultConsts.GOODS_ID_TO_WAP, bannerInfo.getContent());
        //							intent.putExtra(DefaultConsts.WAP_FROM_TYPE, bannerInfo.getType());
        //							bActivity.startActivity(intent);
        //							break;
        //						default:
        //							break;
        //					}
        //
        //				}
        //			});
        //			((ViewPager) container).addView(bannerList.get(curposition));
        //			return bannerList.get(curposition);
        //		}

        @Override
        public Object instantiateItem(View container, int position) {
            if (position >= bannersLength) position = position % bannersLength;
            try {
                ((ViewPager) container).addView(bannerList.get(position));
            } catch (Exception e) {
                e.printStackTrace();
            }
            final EBannerInfo bannerInfo = banners.get(position);
            bannerList.get(position).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {

                    //					Utils.showToast(context, "您点击了" + position + "图片");
                    // type 类型 int  1为单个商品  2 为多个商品
                    switch (bannerInfo.getType()) {
                        case 1:
                            gotoGoodsDetailPage(bannerInfo.getBannerUrl(), "", Long.parseLong(bannerInfo.getContent()), bannerInfo.getType());
                            break;
                        case 2:
                            Intent intent = new Intent(bActivity, bannerListActivity.class);
                            intent.putExtra(DefaultConsts.GOODS_BASE_URL_TO_WAP, bannerInfo.getBannerUrl());
                            intent.putExtra(DefaultConsts.GOODS_ID_TO_WAP, bannerInfo.getContent());
                            intent.putExtra(DefaultConsts.WAP_FROM_TYPE, bannerInfo.getType());
                            bActivity.startActivity(intent);
                            break;
                        default:
                            break;
                    }

                }
            });

            return bannerList.get(position);
        }

        @Override
        public void destroyItem(View container, int position, Object object) {
            if (position >= bannersLength) position = position % bannersLength;
            ((ViewPager) container).removeView(bannerList.get(position));
        }

    }

    /********************************* banner end *********************************************/

    /*******************************
     * 热门活动 start
     **********************************************/
    class RecommendPagerAdapter
            extends
            BaseAdapter {
        @Override
        public int getCount() {
            //			ItemLength = recommendList.size();
            //						return (recommendList == null || recommendList.size() == 0) ?0: recommendList.size();

            //			ItemLength = 4; //数据的真实大小
            recommendItemLength = recommendList.size();
            return (recommendList.size() == 0 || recommendList == null) ? 0 : Integer.MAX_VALUE; //为了循环显示

        }

        /*
         * (non-Javadoc)
         * @see android.widget.Adapter#getItem(int)
         */
        @Override
        public Object getItem(int position) {
            if (position >= recommendItemLength) position = position % recommendItemLength;
            return (recommendList == null || recommendList.size() == 0) ? null : recommendList.get(position);
        }

        /*
         * (non-Javadoc)
         * @see android.widget.Adapter#getItemId(int)
         */
        @Override
        public long getItemId(int position) {
            if (position >= recommendItemLength) position = position % recommendItemLength;
            return position;
        }

        /*
         * (non-Javadoc)
         * @see android.widget.Adapter#getView(int, android.view.View,
         * android.view.ViewGroup)
         */
        @Override
        public View getView(int position, View view, ViewGroup parent) {
            RecommendHolder recommendHolder;
            if (view == null) {
                recommendHolder = new RecommendHolder();
                view = LayoutInflater.from(bActivity).inflate(R.layout.recommend_item, null);
                recommendHolder.ivRecommendCover = (ImageView) view.findViewById(R.id.recommed_item_cover_iv);
                recommendHolder.ivAddShoppingCar = (ImageView) view.findViewById(R.id.recommend_item_add_shopping_car_iv);
                recommendHolder.tvRecommendGoodIntro = (TextView) view.findViewById(R.id.recommend_item_intro_tv);
                recommendHolder.tvRecommendDiscountPrice = (TextView) view.findViewById(R.id.recommend_item_discount_price_tv);
                recommendHolder.tvRecommendOriginalPrice = (TextView) view.findViewById(R.id.recommend_item_original_price_tv);
                view.setTag(recommendHolder);
            } else {
                recommendHolder = (RecommendHolder) view.getTag();
            }

            if (position >= recommendItemLength) position = position % recommendItemLength;
            //			GoodsInfo recommendInfo = recommendList.get(position).getGoodsDto();
            final RecommendInfo info = (RecommendInfo) getItem(position);
            GoodsBaseInfo recommendInfo = info.getGoodsDto();
            //设置默认图片
            if (Utils.isEmpty(recommendInfo.getCoverUrl())) {
                recommendHolder.ivRecommendCover.setImageResource(R.drawable.bg_small_image);
            } else {
                //				recommendHolder.ivRecommendCover.setImageUrl(recommendInfo.getCoverUrl());
                GlideUtil.load(context,recommendInfo.getCoverUrl(), R.drawable.bg_small_image,recommendHolder.ivRecommendCover);
            }
            recommendHolder.tvRecommendGoodIntro.setText(Utils.isEmpty(recommendInfo.getTitle()) ? "" : recommendInfo.getTitle());
            //如果活动价为0，说明该商品没有参加活动，只显示原价
            if (recommendInfo.getActivityPrice() == 0) {
                recommendHolder.tvRecommendDiscountPrice.setText(" ¥" + Double.toString(recommendInfo.getSalePrice()));
                recommendHolder.tvRecommendOriginalPrice.setVisibility(View.GONE);
            } else {
                recommendHolder.tvRecommendDiscountPrice.setText(" ¥" + Utils.getMoneyFormat(MoneyUtil.divide(recommendInfo.getActivityPrice(), 100)));
                recommendHolder.tvRecommendOriginalPrice.setText(" ¥" + Utils.getMoneyFormat(MoneyUtil.divide(recommendInfo.getSalePrice(), 100)));
                recommendHolder.tvRecommendOriginalPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);//设置中画线
                recommendHolder.tvRecommendOriginalPrice.setVisibility(View.VISIBLE);
            }
            recommendHolder.tvRecommendOriginalPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);//设置中画线
            //购物车点击事件
            recommendHolder.ivAddShoppingCar.setVisibility(view.GONE);
            recommendHolder.ivAddShoppingCar.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    //					Utils.showToast(bActivity, "您已成功加入购物车");

                    addToShoppingCarActivity(info.getGoodsDto().getGoodsId(), info.getId(), info.getFreeMoney());
                    //					addToShoppingCar();
                }

            });
            return view;
        }
    }

    class RecommendHolder {
        //热门推荐 item
        private ImageView ivRecommendCover;        //封面
        private ImageView ivAddShoppingCar;        //购物车
        private TextView tvRecommendGoodIntro;    //商品介绍
        private TextView tvRecommendDiscountPrice; // 原价
        private TextView tvRecommendOriginalPrice; //活动价/现价
    }

    /******************************* 热门推荐 end **************************************************/

    /******************************
     * 大家都在买 start
     ***********************************************/
    //大家都在买
    class AllBuyAdapter
            extends
            BaseAdapter {

        @Override
        public int getCount() {
            //			return 3;
            return (allBuyList == null || allBuyList.size() == 0) ? 0 : allBuyList.size();
        }

        @Override
        public Object getItem(int arg0) {

            return (allBuyList == null || allBuyList.size() == 0) ? null : allBuyList.get(arg0);
        }

        @Override
        public long getItemId(int arg0) {

            return arg0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder allBuyViewHolder;
            if (convertView == null) {
                allBuyViewHolder = new ViewHolder();
                convertView = LayoutInflater.from(bActivity).inflate(R.layout.goods_box_list_item, parent, false);
                allBuyViewHolder.ivCover = (ImageView) convertView.findViewById(R.id.good_box_list_item_cover_iv);
                allBuyViewHolder.tvGoodIntro = (TextView) convertView.findViewById(R.id.good_box_list_item_intro_tv);
                allBuyViewHolder.tvDiscountPrice = (TextView) convertView.findViewById(R.id.good_box_list_item_discount_price_tv);
                allBuyViewHolder.tvOriginalPrice = (TextView) convertView.findViewById(R.id.good_box_list_item_original_price_tv);
                allBuyViewHolder.tvAllNumber = (TextView) convertView.findViewById(R.id.good_box_list_item_number_tv);
                convertView.setTag(allBuyViewHolder);
            } else {
                allBuyViewHolder = (ViewHolder) convertView.getTag();
            }
            GoodsBaseInfo info = (GoodsBaseInfo) getItem(position);
            //如果为空显示默认图片
            if (Utils.isEmpty(info.getCoverUrl())) {
                allBuyViewHolder.ivCover.setImageResource(R.drawable.bg_small_image);
            } else {
                GlideUtil.load(context,info.getCoverUrl(), R.drawable.bg_small_image,allBuyViewHolder.ivCover);
                //				allBuyViewHolder.ivCover.setImageUrl(info.getCoverUrl());

            }
            //设置标题
            allBuyViewHolder.tvGoodIntro.setText(Utils.isEmpty(info.getTitle()) ? "" : info.getTitle());
            //设置购买的人数
            allBuyViewHolder.tvAllNumber.setText(info.getSaleNum() == 0 ? "新品上市" : (info.getSaleNum() + "人已经购买"));
            //如果活动价为0，说明该商品没有参加活动，只显示原价
            if (info.getActivityPrice() == 0) {
                allBuyViewHolder.tvDiscountPrice.setText(" ¥" + Utils.getMoneyFormat(MoneyUtil.divide(info.getSalePrice(), 100)));
                allBuyViewHolder.tvOriginalPrice.setVisibility(View.GONE);
            } else {
                allBuyViewHolder.tvDiscountPrice.setText(" ¥" + Utils.getMoneyFormat(MoneyUtil.divide(info.getActivityPrice(), 100)));
                allBuyViewHolder.tvOriginalPrice.setText(" ¥" + Utils.getMoneyFormat(MoneyUtil.divide(info.getSalePrice(), 100)));
                allBuyViewHolder.tvOriginalPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);//设置中画线
                allBuyViewHolder.tvOriginalPrice.setVisibility(View.VISIBLE);
            }
            allBuyViewHolder.tvOriginalPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);//设置中画线
            return convertView;
        }

    }

    class ViewHolder {
        private ImageView ivCover;
        private TextView tvGoodIntro, tvDiscountPrice, tvOriginalPrice, tvAllNumber;
    }

    /************************************** 大家都在买 end *******************************************/

}
